package com.moyu.oasys.attendance.controller;

import com.alibaba.nacos.api.model.v2.Result;
import com.moyu.common.core.domain.R;
import com.moyu.oasys.attendance.AttendanceService;
import com.moyu.oasys.attendance.entity.Attendance;
import com.moyu.oasys.attendance.service.IAttendanceService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 赵彦博
 * @Date 2024/12/2 20:18
 */
@RestController
@RequestMapping("attendances")
public class AttendanceController {

    private final IAttendanceService attendanceService;

    public AttendanceController(IAttendanceService attendanceService) {
        this.attendanceService = attendanceService;
    }

    @GetMapping("/listAttendance")
    public R<List<Attendance>> listAttendance(@RequestParam Long userId, @RequestParam Integer year,
                                              @RequestParam Integer month, Integer day) {
        return R.ok(attendanceService.listByUserIdAndClockDate(userId, year, month, day));
    }

    @PostMapping("/clockIn")
    public R<Attendance> clockIn(@RequestParam Long userId) {
        return R.ok(attendanceService.create(userId));
    }

    @PutMapping("/clockOut")
    public R<Attendance> clockOut(@RequestParam Long id) {
        return R.ok(attendanceService.update(id));
    }

}
